/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sunchangming.benchmark;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;

/**
 * 
 * @author cm
 */
public class perfTest {
	private final static ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
	protected static int global;

	public static void main(String[] args) {
		final long t1 = tmx.getCurrentThreadUserTime();

		int value = 0;
		for (int i = 0; i < 1000 * 1000 * 1000; i++) {
			value = calculate(value);
		}

		final long t2 = tmx.getCurrentThreadUserTime();
		System.out.println("Execution time: " + ((t2 - t1) * 1e-6) + " milliseconds");
	}

	protected static int calculate(int arg) {
		 assert (arg >= 0) : "should be positive";
		//L2: if (arg < 0) throw new IllegalArgumentException("arg = " + arg + " < 0");

		global = arg * 6;
		global += 3;
		global /= 2;
		return arg + 2;
	}
}
